<?php


namespace app\shop\controller\admin;


use app\BaseController;
use app\shop\service\config\ConfigService;
use app\shop\service\until\FileService;

class ConfigController extends BaseController
{
    /**
     * 网站配置
     * @return \think\response\Json
     */
    public function setConfig()
    {
        try {
            $params = $this->request->param();
            foreach ($params as $k => $v) {
                ConfigService::setConfigValue($k, $v);
            }
            return $this->success();
        } catch (\Exception $exception) {
            return $this->error($exception->getMessage());
        }
    }

    /**
     * 获取配置信息
     * @return \think\response\Json
     */
    public function getConfigInfo()
    {
        try {
            $type = $this->request->param('type', 0);
            $list = ConfigService::getTypeConfigValueArray($type);
            return $this->success($list);
        } catch (\Exception $exception) {
            return $this->error($exception->getMessage());
        }
    }

    /**
     * 获取一个配置
     * @return \think\response\Json
     */
    public function getConfigInfoByName()
    {
        try {
            $name = $this->request->param('name', '','trim');
            $configInfo = ConfigService::getConfigValue($name);
            return $this->success($configInfo);
        } catch (\Exception $exception) {
            return $this->error($exception->getMessage());
        }
    }

    public function setSysInfo()
    {
        try {
            $param = $this->request->param('', '','trim');
            $list = ConfigService::setConfigValue('sysInfo',$param);
            return $this->success($list);
        } catch (\Exception $exception) {
            return $this->error($exception->getMessage());
        }
    }

    public function setChatInfo()
    {
        try {
            $param = $this->request->param('', '','trim');
            $list = ConfigService::setConfigValue('chatInfo',$param);
            return $this->success($list);
        } catch (\Exception $exception) {
            return $this->error($exception->getMessage());
        }
    }

    public function setFileUpload()
    {
        try {
            $param = $this->request->param('', '','trim');
            $list = ConfigService::setConfigValue('fileUpload',$param);
            return $this->success();
        } catch (\Exception $exception) {
            return $this->error($exception->getMessage());
        }
    }
}